tests: Always cleanup gpg-agent when exiting
authorDan Nicholson <nicholson@endlessm.com>
Thu, 13 Jun 2019 21:26:47 +0000 (16:26 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 19 Jun 2019 17:30:24 +0000 (17:30 +0000)
Add `libtest_cleanup_gpg()` to the array of commands to run when
exiting. This provides 2 improvements:

1. You don't need to worry about whether the test will spawn a gpg-agent
   and therefore require adding a call to `libtest_cleanup_gpg()`.

2. All the existing users were calling `libtest_cleanup_gpg()` at the
   end of the script. If there was a failure and the script exited
   early, then it wouldn't cleanup and there may be a stray gpg-agent
   hanging around.

Closes: #1799
Approved by: cgwalters

tests/libtest.sh
tests/test-commit-sign.sh
tests/test-gpg-signed-commit.sh
tests/test-pull-mirror-summary.sh
tests/test-pull-summary-sigs.sh
tests/test-remote-gpg-import.sh
tests/test-summary-view.sh

index e70b7b876c36b2c7dfbc56e15031c8ff631beee0..632ccee8ceb67edc424f73988b1f46d4d9f86003 100755 (executable)
@@ -648,6 +648,7 @@ libtest_cleanup_gpg () {
     local gpg_homedir=${1:-${test_tmpdir}/gpghome}
     gpg-connect-agent --homedir "${gpg_homedir}" killagent /bye || true
 }
+libtest_exit_cmds+=(libtest_cleanup_gpg)
 
 is_bare_user_only_repo () {
   grep -q 'mode=bare-user-only' $1/config
index d789d2fb6e5a296ef5e1bfb7c349918cd835f1b3..e9e7a6da06984d09b01b74641448e262e545888b 100755 (executable)
@@ -140,4 +140,3 @@ assert_not_file_has_content show.txt 'Found.*signature'
 echo "ok pull sig deleted"
 
 rm -rf repo gnomerepo-files
-libtest_cleanup_gpg
index 7bd5950291619abe0c5f2f64f4980c952dfe6489..3e41efb82ceacd9a7a4c60dc8d9c305ed300a9f5 100755 (executable)
@@ -89,8 +89,6 @@ if ${OSTREE} show test2 | grep -o 'Found [[:digit:]] signature'; then
   assert_not_reached
 fi
 
-libtest_cleanup_gpg
-
 echo "ok"
 
 # Remaining tests require gpg
index cc3c6a2c4efd30fa96129149e668d0ff573e84c5..504cf545cd0ceeaf6517073149c3ecab6a1bffe0 100755 (executable)
@@ -120,5 +120,3 @@ echo "ok pull mirror with invalid summary sig and no verification"
 # assert_file_has_content deltas.txt "${origmain}-${newmain}"
 
 # echo "ok pull mirror with signed summary covering static deltas"
-
-libtest_cleanup_gpg
index e2864beb4033e33ab916a02108df0f2097406cea..0b6b806cb43c5c96e5bf032026ee059316398d6b 100755 (executable)
@@ -274,5 +274,3 @@ cmp repo/tmp/cache/summaries/origin ${test_tmpdir}/ostree-srv/gnomerepo/summary.
 cmp repo/tmp/cache/summaries/origin.sig ${test_tmpdir}/ostree-srv/gnomerepo/summary.sig.2 >&2
 
 echo "ok pull with signed summary broken cache"
-
-libtest_cleanup_gpg
index 1bb42d82e8ca7fbc89322cfe99104d171d6251a6..4d73fa116459584ba62a42a964fff65f0e30aa66 100755 (executable)
@@ -280,5 +280,3 @@ ${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo summary -u --gpg
 ${OSTREE} pull --require-static-deltas R1:main
 
 echo "ok gpg trusted signed commit for delta upgrades"
-
-libtest_cleanup_gpg
index a5ddf93ed0537c2fe51f78aae6d2198f483f9ea7..d26d343118d40b47ca9a264bb29cbb471d626c45 100755 (executable)
@@ -62,5 +62,3 @@ assert_file_has_content_literal raw-summary.txt "('main', ("
 assert_file_has_content_literal raw-summary.txt "('other', ("
 assert_file_has_content_literal raw-summary.txt "{'ostree.summary.last-modified': <uint64"
 echo "ok view summary raw"
-
-libtest_cleanup_gpg